//
// Created by vcq on 21/2/10.
//
#pragma once
#include "dbng.hpp"
#include "utils_dao.hpp"
#include <string>
using namespace nlohmann;
using namespace std;
using Dao = dao_t<dbng<mysql>>;
struct profession {
    int id;
    string name;
    string note;
    int _school_id;
};
REFLECTION(profession, id, name, _school_id, note)

json mgetProfession(basic_string_view<char> id,basic_string_view<char> _school_id){
    string sql="select * from profession where 1=1 ";
    if (!id.empty()) {
        sql += "and id =";
        sql += id;
    }
    if (!id.empty()) {
        sql += "and _school_id =";
        sql += _school_id;
    }
    Dao dao;
    auto v = dao.query<profession>(sql);
    nlohmann::json article_list,ret,item;
    for (auto& o : v) {
        item["id"]=o.id;
        item["name"] = o.name;
        item["note"] = o.note;
        item["_school_id"] = o._school_id;
        article_list.push_back(item);
    }
    ret["code"] = 0;
    ret["count"] = article_list.size();
    ret["data"] = article_list;
    return ret;
}

void MAddProfession(const struct profession &profession1) {
    Dao dao;
    dao.update_object(profession1);
}

void MDeleteProfession(basic_string_view<char> id) {
    MDeleteAll("profession", id);
}